package com.zjy.business.system.manager.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.github.pagehelper.PageInfo;
import com.zjy.business.system.domain.entity.SysRole;
import com.zjy.business.system.domain.manager.form.ManagerSysRoleSaveOrUpdateForm;
import com.zjy.business.system.domain.manager.query.ManagerListPageSysRoleQuery;
import com.zjy.business.system.domain.manager.vo.ManagerListPageSysRoleVo;
import com.zjy.business.system.manager.service.ManagerSysRoleService;
import com.zjy.log.annotation.OperationLog;
import com.zjy.log.enums.LogBusinessType;
import com.zjy.web.domain.model.Result;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台管理-角色管理
 */
@RestController
@RequestMapping("/manager/sysRole")
@Validated
@RequiredArgsConstructor
public class ManagerSysRoleController {

    final private ManagerSysRoleService managerSysRoleService;

    private static final String MODULE_NAME = "角色管理";

    /**
     * 新增或者修改角色
     */
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.INSERT_UPDATE)
    @SaCheckPermission("system:sysRole:save_update")
    @PostMapping("/saveOrUpdate")
    public Result<Void> saveOrUpdate(@RequestBody ManagerSysRoleSaveOrUpdateForm form) {
        managerSysRoleService.saveOrUpdateRole(form);
        return Result.SUCCESS();
    }

    /**
     * 删除角色
     * @param id id
     */
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.DELETE)
    @GetMapping("/remove")
    @SaCheckPermission("system:sysRole:remove")
    public Result<Void> remove(@NotNull(message = "id不能为空") Long id) {
        managerSysRoleService.remove(id);
        return Result.SUCCESS();
    }

    /**
     * 角色分页列表
     */
    @GetMapping("/listPageSysRole")
    @SaCheckPermission("system:sysRole:pageList")
    public Result<PageInfo<ManagerListPageSysRoleVo>> listPageSysRole(ManagerListPageSysRoleQuery query) {
        return Result.SUCCESS(managerSysRoleService.listPageSysRole(query));
    }

    /**
     * 角色下拉列表
     * @return
     */
    @GetMapping("/roleDownList")
    public Result<List<SysRole>> roleDownList() {
        return Result.SUCCESS(managerSysRoleService.roleDownList());
    }

}
